<?php

include_once 'templateSys/SQL.php';
include_once 'templateSys/Settings.php';
include_once 'templateSys/manager_util.php';
include_once 'templateSys/Admin.php';
include_once Settings::$template_path . 'templateSource.php';

global $link;

$link = getLink();

checkUser();

if (isset($_GET["lang"])){
    setcookie("lang",  addslashes($_GET["lang"]),time()+60*60*24*30,"/");
}

$pageFound = false;
if (isset($_GET['action'])) {
    if (isset($GLOBALS['user']) && getUser()->getRole() == "admin") {
        foreach ($adminOnly as $variable) {
            if ($variable == $_GET['action']) {
                $pageFound = true;
                echo parseTemplate(loadTemplate($variable));
                break;
            }
        }
    }

    if (!$pageFound) {
        foreach ($pages as $variable) {
            if (isset($_GET['action']) && $variable == $_GET['action']) {
                $pageFound = true;
                if (isset($GLOBALS['user']) && isset($_GET['preview']) && $_GET['preview'] == 1) {
                    echo parseTemplatePreview(loadTemplate($variable));
                } else {
                    echo parseTemplate(loadTemplate($variable));
                }
                break;
            }
        }
    }
}else{
    $pageFound = true;
    $variable = Settings::$afterLoginPage;
    echo parseTemplate(loadTemplate($variable));
}

if (!$pageFound) {
    echo parseTemplate(loadTemplate("error"));
}

mysql_close($link);
?>
